/*
 * @Author: Crism
 * @Date: 2018-08-03 16:18:12
 * @LastEditors: Crism
 * @LastEditTime: 2018-08-03 16:50:27
 * @Description: 
 * @Email: crism@qq.com
 */

const request = require('request');
const fs = require('fs');


module.exports.downloadImg = downloadImg;
module.exports.mkdirSync = mkdirSync;

async function downloadImg(url) {
    if(url != undefined) {
        request(url).pipe(fs.createWriteStream('./authorportrait/' + url.slice(url.lastIndexOf('/') + 1)));
    }
}

async function mkdirSync(dirname) {
    if (fs.existsSync(dirname)) {
        return true;
    } else {
        if (mkdirSync(path.dirname(dirname))) {   
            fs.mkdirSync(dirname);
            return true;
        }
    }
    return false;
}